<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item custom-form-item">
                        <div class="layui-inline">
                            <input type="checkbox" name="filterUsers" lay-skin="primary" lay-filter="filterUsers"
                                   title="过滤无效用户" checked>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-warm layui-btn-sm data-add-btn" lay-event="exportBtn"> 导出</button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

    </div>
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../lib/common/common.js" charset="utf-8"></script>
<script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script>

    let filterUsers = true;

    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/sys/user/page/list',
            where: {
                filterUsers: true
            },
            method: 'GET',
            contentType: 'application/x-www-form-urlencoded',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {
                    field: 'numbering', title: '序号', width: 60, align: 'center', templet: function (d) {
                        return d.LAY_INDEX; //返回序号
                    }
                },
                {field: 'userId', title: '平台ID', align: 'center'},
                {field: 'nickName', title: '平台昵称', align: 'center'},
                {field: 'phone', title: '关联手机', align: 'center'},
                {field: 'realName', title: '真实姓名', align: 'center'},
                {field: 'sex', title: '性别', align: 'center'},
                {field: 'ageGroup', title: '年龄层', align: 'center'},
                {field: 'region', title: '所在地区', align: 'center'},
                {field: 'streetVillage', title: '所在街道', align: 'center'},
                {field: 'address', title: '详细地址', align: 'center'},
                {field: 'identityJob', title: '身份职业', align: 'center'},
                {field: 'monthlyIncome', title: '月收入', align: 'center'},
                {
                    field: 'subscribedWx', title: '绑定公众号（是/否）', sort: true, align: 'center', templet: function (d) {
                        if (d.subscribedWx === '1') {
                            return '<span style="color:#4fc44f;">是</span>'
                        } else {
                            return '<span style="color:#ff0000;">否</span>'
                        }
                    }
                },
                {
                    field: 'isEvaluator', title: '测评师（是/否）', sort: true, align: 'center', templet: function (d) {
                        if (d.isEvaluator === '是') {
                            return '<span style="color:#4fc44f;">是</span>'
                        } else {
                            return '<span style="color:#ff0000;">否</span>'
                        }
                    }
                },
                {
                    field: 'isProvider', title: '区域服务商（是/否）', sort: true, align: 'center', templet: function (d) {
                        if (d.isProvider === '是') {
                            return '<span style="color:#4fc44f;">是</span>'
                        } else {
                            return '<span style="color:#ff0000;">否</span>'
                        }
                    }
                },
                {field: 'createTime', title: '注册时间', sort: true, align: 'center'},
            ]],
            limits: [50, 100, 150, 200, 250, 300],
            limit: 50,
            page: true,
            request: {
                pageName: 'pageNum',
                limitName: 'pageSize'
            },
            response: { //定义后端 json 格式，详细参见官方文档
                statusName: 'code', //状态字段名称
                statusCode: '200', //状态字段成功值
                msgName: 'msg', //消息字段
                countName: 'total', //总数字段
                dataName: 'rows' //数据字段
            },
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'exportBtn') {  // 监听导出操作
                const data = {
                    filterUsers: filterUsers
                }
                downloadExcel('/sys/user/list/export', data, '客户列表.xlsx', 'POST')
            }
            return false;
        });

        form.on('checkbox(filterUsers)', function (data) {
            if (data.elem.checked) { //判断复选框是否选中
                filterUsers = true;
            } else {
                filterUsers = false;
            }
            reloadTable();
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            return false;
        });

    });

    /**
     * 重载表格数据
     */
    function reloadTable() {
        layui.use(['table'], function () {
            let table = layui.table;
            table.reload('currentTableId', {
                url: '/sys/user/page/list',
                where: {
                    filterUsers: filterUsers
                }
            });
        })
    }
</script>

</body>
</html>